<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="jakarta.tags.core" %>
<%@ taglib prefix="fmt" uri="jakarta.tags.fmt" %>
<html>
<head>
    <title>问卷详情</title>
    <style>
        .container {
            width: 800px;
            margin: 50px auto;
            padding: 20px;
        }
        .survey-header {
            margin-bottom: 20px;
            padding-bottom: 10px;
            border-bottom: 1px solid #ddd;
        }
        .btn {
            display: inline-block;
            padding: 8px 16px;
            margin: 5px;
            background-color: #4CAF50;
            color: white;
            text-decoration: none;
            border-radius: 4px;
        }
        .btn-back {
            background-color: #666;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="survey-header">
            <h2>${survey.title}</h2>
            <p>创建时间：<fmt:formatDate value="${survey.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/></p>
            <p>状态：
                <c:choose>
                    <c:when test="${survey.status == 0}">草稿</c:when>
                    <c:when test="${survey.status == 1}">已发布</c:when>
                    <c:when test="${survey.status == 2}">已结束</c:when>
                </c:choose>
            </p>
        </div>
        <div class="survey-content">
            <h3>问卷说明</h3>
            <p>${survey.description}</p>
        </div>
        <div class="actions">
            <a href="${pageContext.request.contextPath}/survey/list" class="btn btn-back">返回列表</a>
            <c:if test="${survey.userId eq user.id}">
                <a href="javascript:void(0)" onclick="deleteSurvey(${survey.id})" class="btn">删除问卷</a>
            </c:if>
        </div>
    </div>
    
    <script>
    function deleteSurvey(id) {
        if(confirm('确定要删除这个问卷吗？')) {
            fetch('${pageContext.request.contextPath}/survey/delete/' + id, {
                method: 'POST'
            }).then(response => response.text())
              .then(result => {
                  if(result === 'success') {
                      window.location.href = '${pageContext.request.contextPath}/survey/list';
                  } else {
                      alert('删除失败');
                  }
              });
        }
    }
    </script>
</body>
</html>
